<?php

namespace app\ljhs\controller;
use app\common\controller\Ljhs;
use app\admin\model\AdminLog;
use fast\Random;
use think\Config;
use think\Hook;
use think\Validate;
/**
 * 分拣员接口
 */
class Sorting extends Ljhs
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    /**
     * 成品入库
     * @return void
     */
    public function cprk()
    {
        $num = $this->request->post('num');
        if(!$num){
            $this->error(__('参数错误'));
        }
        $user = $this->auth->getUserInfo();
        $params = $this->request->post();
        $params['user_id'] = $user['id'];
        $params['stand_id'] = $user['stand_id'];
        $params['createtime'] = time();
        $res = \app\common\model\Cprk::create($params);
        if($res){
            //更新此站点的库存
            $stand = \app\common\model\Stand::get($user['stand_id']);
            $stand->stock = $stand->stock + $num;
            $stand->db_num = $stand->db_num + $num;
            $stand->save();
            $this->success(__('提交成功'));
        }else{
            $this->error(__('提交失败'));
        }
    }

    /**
     * 打包机检测
     * @return void
     */
    public function balercheck()
    {
        $user = $this->auth->getUserInfo();
        if($user['groups']['group_id'] != 7){
//            $this->error(__('您没有权限'));
        }
        $params = $this->request->post();
        if(!isset($params['yyy_status']) || !isset($params['rhy_status']) || !isset($params['dbs_status'])){
            $this->error(__('参数错误'));
        }
        $params['user_id'] = $user['id'];
        $params['stand_id'] = $user['stand_id'];
        $params['createtime'] = time();
        $res = \app\common\model\Balercheck::create($params);
        if($res){
            $this->success(__('提交成功'));
        }else{
            $this->error(__('提交失败'));
        }
    }

    /**
     * 打包机维修
     * @return void
     */
    public function balerRepair()
    {
        $user = $this->auth->getUserInfo();
        $params = $this->request->post();
        if(!isset($params['comrepair_id']) || !isset($params['gz_images']) || !isset($params['price'])){
            $this->error(__('参数错误'));
        }
        $params['user_id'] = $user['id'];
        $params['stand_id'] = $user['stand_id'];
        $params['createtime'] = time();
        $res = \app\common\model\Balerrepair::create($params);
        if($res){
            $this->success(__('提交成功'));
        }else{
            $this->error(__('提交失败'));
        }
    }

    /**
     * 叉车车况检测
     * @return void
     */
    public function forkcarcheck()
    {
        $user = $this->auth->getUserInfo();
//        if($user['groups']['group_id'] != 7){
//            $this->error(__('您没有权限'));
//        }
        $params = $this->request->post();
        if(!isset($params['oil_num']) || !isset($params['km'])){
            $this->error(__('参数错误'));
        }
        $params['user_id'] = $user['id'];
        $params['stand_id'] = $user['stand_id'];
        $params['createtime'] = time();
        $res = \app\common\model\Forkcarcheck::create($params);
        if($res){
            $this->success(__('提交成功'));
        }else{
            $this->error(__('提交失败'));
        }
    }


    /**
     * 叉车加油
     * @return void
     */
    public function forkcarjy()
    {
        $user = $this->auth->getUserInfo();
        $params = $this->request->post();
        if(!isset($params['rise_num']) || !isset($params['km']) || !isset($params['price'])){
            $this->error(__('参数错误'));
        }
        $params['user_id'] = $user['id'];
        $params['stand_id'] = $user['stand_id'];
        //计算每小时油耗多少升
        $params['yh_num'] = round($params['km'] / $params['rise_num'],2);
        $params['yh_price'] = round($params['price'] / $params['rise_num'],2);
        $params['createtime'] = time();
        $res = \app\common\model\Forkcarjy::create($params);
        if($res){
            $this->success(__('提交成功'));
        }else{
            $this->error(__('提交失败'));
        }
    }


    /**
     * 叉车车辆维修
     * @return void
     */
    public function forkCarRepair()
    {
        $user = $this->auth->getUserInfo();
        $params = $this->request->post();
        if(!isset($params['comrepair_id']) || !isset($params['km']) || !isset($params['price'])){
            $this->error(__('参数错误'));
        }
        $params['user_id'] = $user['id'];
        $params['stand_id'] = $user['stand_id'];
        $params['createtime'] = time();
        $res = \app\common\model\Forkcarrepair::create($params);
        if($res){
            $this->success(__('提交成功'));
        }else{
            $this->error(__('提交失败'));
        }
    }




}
